/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJInternalFrame.java
 *
 * Created on 18/06/2009, 21:18:40
 */

package pizarra.vistas;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

import pizarra.Controlador;
import pizarra.Linea;
import pizarra.Pizarra;
import pizarra.TransferableImage;

/**
 *
 * @author Christian
 */
public class VistaPizarra extends javax.swing.JInternalFrame {

  	private static final long serialVersionUID = 1L;
	private VistaPrincipal mdi;
	private Controlador controlador;
	private Pizarra pizarra;
	private File archivoPizarra;
    
    /** Creates new form NewJInternalFrame */
    public VistaPizarra(Controlador c, VistaPrincipal mdi, Pizarra p, File archivo, int ancho, int alto) {
        this.controlador = c;
        this.mdi = mdi;
        pizarra = p;
        archivoPizarra = archivo;
        initComponents(ancho, alto);

        setLocation(VistaPrincipal.SEPARACION*VistaPrincipal.inset, VistaPrincipal.SEPARACION*VistaPrincipal.inset);
        ++VistaPrincipal.inset;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents(int ancho, int alto) {

        barraHerramientasToolBar = new javax.swing.JToolBar();
        guardarButton = new javax.swing.JButton();
        guardarComoButton = new javax.swing.JButton();
        exportarButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        cortarButton = new javax.swing.JButton();
        copiarButton = new javax.swing.JButton();
        colorButton = new javax.swing.JButton();
        limpiarButton = new javax.swing.JButton();
        panel = new javax.swing.JPanel() {
			private static final long serialVersionUID = 1L;

			@Override
			public void paint(java.awt.Graphics g) {
				g.setColor(pizarra.getFondo());
				g.fillRect(0, 0, panel.getWidth(), panel.getHeight());
				for(Linea linea : pizarra.getLineas()){
					g.setColor(linea.getColor());
					g.drawPolyline(linea.getPuntosX(), linea.getPuntosY(), linea.getCantidadPuntos());
				}
			};
        };
        jMenuBar1 = new javax.swing.JMenuBar();
        archivoMenu = new javax.swing.JMenu();
        guardarMenuItem = new javax.swing.JMenuItem();
        guardarComoMenuItem = new javax.swing.JMenuItem();
        exportarMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        cerrarMenuItem = new javax.swing.JMenuItem();
        edicionMenu = new javax.swing.JMenu();
        cortarMenuItem = new javax.swing.JMenuItem();
        copiarMenuItem = new javax.swing.JMenuItem();
        formatoMenu = new javax.swing.JMenu();
        seleccionarColorMenu = new javax.swing.JMenu();
        seleccionarColorPopupMenu = new javax.swing.JPopupMenu();
        limpiarMenuItem = new javax.swing.JMenuItem();
        verMenu = new javax.swing.JMenu();
        barraHerramientasCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        fondoMenuItem = new javax.swing.JMenuItem();
        coloresMenuItem = new javax.swing.JMenuItem[10];
        fondoPopupMenuItem = new javax.swing.JMenuItem();
        coloresPopupMenuItem = new javax.swing.JMenuItem[10];
        
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        barraHerramientasToolBar.setRollover(true);
        barraHerramientasToolBar.setPreferredSize(new java.awt.Dimension(100, 25));
        
        guardarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/45.png"))); // NOI18N
        guardarButton.setToolTipText("Guardar Pizarra");
        guardarButton.setFocusable(false);
        guardarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        guardarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        guardarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarActionPerformed(evt);
            }
        });
        barraHerramientasToolBar.add(guardarButton);

        guardarComoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/46.png"))); // NOI18N
        guardarComoButton.setToolTipText("Guardar Pizarra como...");
        guardarComoButton.setFocusable(false);
        guardarComoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        guardarComoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        guardarComoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarComoActionPerformed(evt);
            }
        });
        barraHerramientasToolBar.add(guardarComoButton);
        barraHerramientasToolBar.add(jSeparator3);

        exportarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/20.png"))); // NOI18N
        exportarButton.setToolTipText("Exportar como JPG...");
        exportarButton.setFocusable(false);
        exportarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        exportarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        exportarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportarActionPerformed(evt);
            }
        });
        barraHerramientasToolBar.add(exportarButton);
        barraHerramientasToolBar.add(jSeparator3);

        cortarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/101.png"))); // NOI18N
        cortarButton.setToolTipText("Cortar");
        cortarButton.setFocusable(false);
        cortarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cortarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cortarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cortarButtonActionPerformed(evt);
            }
        });
        barraHerramientasToolBar.add(cortarButton);

        copiarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/102.png"))); // NOI18N
        copiarButton.setToolTipText("Copiar");
        copiarButton.setFocusable(false);
        copiarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        copiarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        copiarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copiarButtonActionPerformed(evt);
            }
        });
        barraHerramientasToolBar.add(copiarButton);
        
        limpiarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/01.png"))); // NOI18N
        limpiarButton.setToolTipText("Limpiar Pizarra");
        limpiarButton.setFocusable(false);
        limpiarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        limpiarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        limpiarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiarButtonActionPerformed(evt);
            }
        });
        barraHerramientasToolBar.add(limpiarButton);

        barraHerramientasToolBar.add(jSeparator4);

        colorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/colorPicker.png"))); // NOI18N
        colorButton.setToolTipText("Seleccionar Colores");
        colorButton.setFocusable(false);
        colorButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        colorButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        colorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                colorButtonActionPerformed(evt);
            }
        });
        barraHerramientasToolBar.add(colorButton);

        getContentPane().add(barraHerramientasToolBar, java.awt.BorderLayout.NORTH);

        panel.setPreferredSize(new Dimension(ancho, alto));
        getContentPane().add(panel, java.awt.BorderLayout.CENTER);

        archivoMenu.setText("Archivo");

        guardarMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        guardarMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/45.png"))); // NOI18N
        guardarMenuItem.setText("Guardar Pizarra");
        guardarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarMenuItemActionPerformed(evt);
            }
        });
        archivoMenu.add(guardarMenuItem);

        guardarComoMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/46.png"))); // NOI18N
        guardarComoMenuItem.setText("Guardar Pizarra como...");
        guardarComoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarComoMenuItemActionPerformed(evt);
            }
        });
        archivoMenu.add(guardarComoMenuItem);

        exportarMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/20.png"))); // NOI18N
        exportarMenuItem.setText("Exportar como JPG...");
        exportarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportarMenuItemActionPerformed(evt);
            }
        });
        archivoMenu.add(exportarMenuItem);
        archivoMenu.add(jSeparator1);

        cerrarMenuItem.setText("Cerrar");
        cerrarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cerrarMenuItemActionPerformed(evt);
            }
        });
        archivoMenu.add(cerrarMenuItem);

        jMenuBar1.add(archivoMenu);

        edicionMenu.setText("Edición");

        cortarMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        cortarMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/101.png"))); // NOI18N
        cortarMenuItem.setText("Cortar");
        cortarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cortarMenuItemActionPerformed(evt);
            }
        });
        edicionMenu.add(cortarMenuItem);

        copiarMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        copiarMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/102.png"))); // NOI18N
        copiarMenuItem.setText("Copiar");
        copiarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copiarMenuItemActionPerformed(evt);
            }
        });
        edicionMenu.add(copiarMenuItem);

        edicionMenu.add(jSeparator2);

        limpiarMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, java.awt.event.InputEvent.CTRL_MASK));
        limpiarMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/01.png"))); // NOI18N
        limpiarMenuItem.setText("Limpiar Pizarra");
        limpiarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiarMenuItemActionPerformed(evt);
            }
        });
        edicionMenu.add(limpiarMenuItem);

        jMenuBar1.add(edicionMenu);

        formatoMenu.setText("Formato");

        seleccionarColorMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pizarra/vistas/iconos/colorPicker.png"))); // NOI18N
        seleccionarColorMenu.setText("Seleccionar Colores");
       
        formatoMenu.add(seleccionarColorMenu);

        jMenuBar1.add(formatoMenu);

        fondoMenuItem.setIcon(getColorIcon(pizarra.getFondo()));
        fondoMenuItem.setText("Fondo");
        fondoMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fondoActionPerformed(e);
			}
		});
        seleccionarColorMenu.add(fondoMenuItem);
        
        fondoPopupMenuItem.setIcon(getColorIcon(pizarra.getFondo()));
        fondoPopupMenuItem.setText("Fondo");
        fondoPopupMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fondoActionPerformed(e);
			}
		});
        seleccionarColorPopupMenu.add(fondoPopupMenuItem);
        
        for (int i = 0; i < 10; i++) {
        	coloresMenuItem[i] = new JMenuItem();
        	coloresMenuItem[i].setIcon(getColorIcon(pizarra.getColor(i)));
        	coloresMenuItem[i].setText("Puntero " + (i + 1));
        	coloresMenuItem[i].setActionCommand("" + i);
        	coloresMenuItem[i].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					coloresActionPerformed(e);
				}
			});
        	seleccionarColorMenu.add(coloresMenuItem[i]);
        	
        	coloresPopupMenuItem[i] = new JMenuItem();
        	coloresPopupMenuItem[i].setIcon(getColorIcon(pizarra.getColor(i)));
        	coloresPopupMenuItem[i].setText("Puntero " + (i + 1));
        	coloresPopupMenuItem[i].setActionCommand("" + i);
        	coloresPopupMenuItem[i].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					coloresActionPerformed(e);
				}
			});
        	seleccionarColorPopupMenu.add(coloresPopupMenuItem[i]);
        }
        
        verMenu.setText("Ver");

        barraHerramientasCheckBoxMenuItem.setSelected(true);
        barraHerramientasCheckBoxMenuItem.setText("Mostrar Barra Herramientas");
        barraHerramientasCheckBoxMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                barraHerramientasCheckBoxMenuItemActionPerformed(evt);
            }
        });
        verMenu.add(barraHerramientasCheckBoxMenuItem);

        jMenuBar1.add(verMenu);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fondoActionPerformed(ActionEvent e) {
    	Color nuevoColor = JColorChooser.showDialog(this, "Seleccionar color de fondo", pizarra.getFondo());
    	if (nuevoColor != null) {
    		pizarra.setFondo(nuevoColor);
    		fondoMenuItem.setIcon(getColorIcon(nuevoColor));
    		fondoPopupMenuItem.setIcon(getColorIcon(nuevoColor));
    		repaint();
    	}
    }
    
    private void coloresActionPerformed(ActionEvent e) {
		int puntero;
		try {
			puntero = Integer.parseInt(((JMenuItem) e.getSource()).getActionCommand());
			Color nuevoColor = JColorChooser.showDialog(this, "Seleccionar color de puntero " + (puntero + 1), pizarra.getFondo());
	    	if (nuevoColor != null) {
	    		pizarra.setColor(puntero, nuevoColor);
	    		coloresMenuItem[puntero].setIcon(getColorIcon(nuevoColor));
	    		coloresPopupMenuItem[puntero].setIcon(getColorIcon(nuevoColor));
	    	}
		} catch (NumberFormatException ex) {}
	}
    
    public Icon getColorIcon(final Color color) {
    	return new Icon() {
			@Override
			public void paintIcon(Component c, Graphics g, int x, int y) {
					g.setColor(color);
					g.fillRect(x, y, 16, 16);
			}

			@Override
			public int getIconWidth() {
				return 16;
			}

			@Override
			public int getIconHeight() {
				return 16;
			}};
    }
    
    private void barraHerramientasCheckBoxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_barraHerramientasCheckBoxMenuItemActionPerformed
        barraHerramientasToolBar.setVisible(!barraHerramientasToolBar.isVisible());
    }//GEN-LAST:event_barraHerramientasCheckBoxMenuItemActionPerformed

    private void cortarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cortarMenuItemActionPerformed
    	copiarMenuItem.doClick();
    	controlador.doLimpiarPizarra(pizarra);
    }//GEN-LAST:event_cortarMenuItemActionPerformed

    private BufferedImage getBufferedImage() {
    	BufferedImage bi = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_RGB);
		Graphics2D g2 = bi.createGraphics();
		panel.paint(g2);
		g2.dispose();
		return bi;
    }
    
    private void copiarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copiarMenuItemActionPerformed
    	TransferableImage trans = new TransferableImage(getBufferedImage());
		Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
		c.setContents(trans, new ClipboardOwner() {
			@Override
			public void lostOwnership(Clipboard clipboard, Transferable contents) {}
		});
		mdi.setEstado("Pizarra copiada al portapapeles");
    }//GEN-LAST:event_copiarMenuItemActionPerformed

    private void limpiarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copiarMenuItemActionPerformed
    	controlador.doLimpiarPizarra(pizarra);
    }//GEN-LAST:event_copiarMenuItemActionPerformed

    private void guardarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarMenuItemActionPerformed
        if (archivoPizarra != null) {
        	try {
				controlador.doGuardar(pizarra, archivoPizarra);
			} catch (FileNotFoundException e) {
				JOptionPane.showMessageDialog(this, "Archivo no encontrado.", "Error", JOptionPane.WARNING_MESSAGE);
			} catch (IOException e) {
				JOptionPane.showMessageDialog(this, "Error al guardar.", "Error", JOptionPane.WARNING_MESSAGE);
			}
        } else
        	guardarComoMenuItem.doClick();
    }//GEN-LAST:event_guardarMenuItemActionPerformed

    private void guardarComoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarMenuItemActionPerformed
    	File anteriorArchivoPizarra = archivoPizarra;
    	JFileChooser fileChooser = new JFileChooser();
		fileChooser.setFileFilter(new FileNameExtensionFilter("Dibujo PMT (*.pmt)", "pmt"));
		fileChooser.setAcceptAllFileFilterUsed(false);
		fileChooser.setDialogTitle("Guardar como...");
		if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
			String file = fileChooser.getSelectedFile().getAbsolutePath();
			if (fileChooser.getSelectedFile().getName().indexOf(".") == -1)
				file += ".pmt";
			archivoPizarra = new File(file);
		
			try {
				controlador.doGuardar(pizarra, archivoPizarra);
				String nuevoTitulo = archivoPizarra.getName().substring(0, archivoPizarra.getName().indexOf(".")) + getTitle().substring(getTitle().indexOf(" - "));
				mdi.actualizarFrame(getTitle(), nuevoTitulo);
				setTitle(nuevoTitulo);
			} catch (FileNotFoundException e) {
				JOptionPane.showMessageDialog(this, "Archivo no encontrado.", "Error", JOptionPane.WARNING_MESSAGE);
				archivoPizarra = anteriorArchivoPizarra;
			} catch (IOException e) {
				JOptionPane.showMessageDialog(this, "Error al guardar.", "Error", JOptionPane.WARNING_MESSAGE);
				archivoPizarra = anteriorArchivoPizarra;
			}
		}
    }//GEN-LAST:event_guardarMenuItemActionPerformed

    private void exportarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarMenuItemActionPerformed
		JFileChooser fileChooser = new JFileChooser();
		fileChooser.setFileFilter(new FileNameExtensionFilter("Imagen JPG (*.jpg)", "jpg"));
		fileChooser.setAcceptAllFileFilterUsed(false);
		fileChooser.setDialogTitle("Exportar...");
		if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
			String file = fileChooser.getSelectedFile().getAbsolutePath();
			if (fileChooser.getSelectedFile().getName().indexOf(".") == -1)
				file += ".jpg";
			try {	
				ImageIO.write(getBufferedImage(), "jpg", new File(file));
				mdi.setEstado("Pizarra exportada");
			} catch(IOException ioe) {
				JOptionPane.showMessageDialog(this, "Error al exportar imagen.", "Error", JOptionPane.WARNING_MESSAGE);
			}
		}
    }//GEN-LAST:event_guardarMenuItemActionPerformed

    private void cerrarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cerrarMenuItemActionPerformed
        mdi.cerrarFrame(this);
    }//GEN-LAST:event_cerrarMenuItemActionPerformed

    private void cortarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cortarButtonActionPerformed
        cortarMenuItem.doClick();
    }//GEN-LAST:event_cortarButtonActionPerformed

    private void copiarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copiarButtonActionPerformed
        copiarMenuItem.doClick();
    }//GEN-LAST:event_copiarButtonActionPerformed

    private void colorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copiarButtonActionPerformed
        seleccionarColorPopupMenu.show(this, MouseInfo.getPointerInfo().getLocation().x - getLocationOnScreen().x, MouseInfo.getPointerInfo().getLocation().y - getLocationOnScreen().y);
    }//GEN-LAST:event_copiarButtonActionPerformed

    private void limpiarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copiarButtonActionPerformed
        limpiarMenuItem.doClick();
    }//GEN-LAST:event_copiarButtonActionPerformed

    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
        mdi.cerrarFrame(this);
    }//GEN-LAST:event_formInternalFrameClosed

    private void guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        guardarMenuItem.doClick();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void guardarComoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        guardarComoMenuItem.doClick();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void exportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        exportarMenuItem.doClick();
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu archivoMenu;
    private javax.swing.JCheckBoxMenuItem barraHerramientasCheckBoxMenuItem;
    private javax.swing.JToolBar barraHerramientasToolBar;
    private javax.swing.JMenuItem cerrarMenuItem;
    private javax.swing.JButton copiarButton;
    private javax.swing.JMenuItem copiarMenuItem;
    private javax.swing.JButton cortarButton;
    private javax.swing.JMenuItem cortarMenuItem;
    private javax.swing.JMenu seleccionarColorMenu;
    private javax.swing.JButton colorButton;
    private javax.swing.JMenu edicionMenu;
	private JButton exportarButton;
    private javax.swing.JMenu formatoMenu;
	private JButton guardarButton;
	private JButton guardarComoButton;
    private javax.swing.JMenuItem guardarMenuItem;
    private javax.swing.JMenuItem guardarComoMenuItem;
    private javax.swing.JMenuItem exportarMenuItem;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JMenuItem limpiarMenuItem;
    private javax.swing.JButton limpiarButton;
    private javax.swing.JMenu verMenu;
    private javax.swing.JPanel panel;
    private javax.swing.JMenuItem fondoMenuItem;
    private javax.swing.JMenuItem fondoPopupMenuItem;
    private javax.swing.JMenuItem[] coloresMenuItem;
    private javax.swing.JMenuItem[] coloresPopupMenuItem;
    private javax.swing.JPopupMenu seleccionarColorPopupMenu;
    // End of variables declaration//GEN-END:variables

}
